package com.nwork.cateye.fragment;

import android.media.Image;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.nwork.cateye.R;

/**
 * 影院Fragment
 */
public class CinemaFragment extends Fragment implements RadioGroup.OnCheckedChangeListener, View.OnClickListener {

    private RadioGroup radioGroup;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    private RadioButton btnTotal;
    private RadioButton btnChoice;
    private RadioButton btnBuy;
    private LinearLayout linearLayout;
    private ImageView imgFilter;
    private TextView txtFilter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_cinema, container, false);
        radioGroup = (RadioGroup)view.findViewById(R.id.cinema_radioGroup);
        btnTotal = (RadioButton)view.findViewById(R.id.cinema_radio_total);
        btnChoice = (RadioButton)view.findViewById(R.id.cinema_radio_choice);
        btnBuy = (RadioButton)view.findViewById(R.id.cinema_radio_buy);
        linearLayout = (LinearLayout)view.findViewById(R.id.cinema_linear_filter);
        imgFilter = (ImageView)view.findViewById(R.id.cinema_image_filter);
        txtFilter = (TextView)view.findViewById(R.id.cinema_txt_filter);
        linearLayout.setOnClickListener(this);
        radioGroup.setOnCheckedChangeListener(this);
        return view;
    }

    /**
     * RadioButton 的点击事件处理
     * @param group
     * @param checkedId
     */
    @Override
    public void onCheckedChanged (RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.cinema_radio_total:
                btnTotal.setTextColor(0xffffffff);
                btnChoice.setTextColor(0xffd53f38);
                btnBuy.setTextColor(0xffd53f38);
                break;
            case R.id.cinema_radio_choice:
                btnTotal.setTextColor(0xffd53f38);
                btnChoice.setTextColor(0xffffffff);
                btnBuy.setTextColor(0xffd53f38);
                break;
            case R.id.cinema_radio_buy:
                btnTotal.setTextColor(0xffd53f38);
                btnChoice.setTextColor(0xffd53f38);
                btnBuy.setTextColor(0xffffffff);
                break;
        }
    }

    /**
     * 筛选按钮点击事件的处理
     * @param v
     */
    @Override
    public void onClick (View v) {
        int id = v.getId();
        switch (id){
            case R.id.cinema_linear_filter:
                linearLayout.setBackgroundColor(0xffd53f38);
                imgFilter.setImageResource(R.drawable.ic_cinema_select_press);
                txtFilter.setTextColor(0xffffffff);
                break;
        }
    }
}
